{extend name="index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">水票管理</div>
    <div class="layui-card-body">
        <div class="layui-form">
            <table class="layui-hide" id="currentTable" lay-filter="currentTable"
                   data-auth-add="{:$auth->check('tickets.tickets/add')}"
                   data-auth-edit="{:$auth->check('tickets.tickets/edit')}"
                   data-auth-delete="{:$auth->check('tickets.tickets/del')}"></table>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/html" id="picTpl">

    <img style="max-width:80px; max-height:30px;" src="{{d.img}}" data-image="{{d.name}}">

</script>
<script type="text/html" id="imgTpl">
    <img src="{{ d.img }}">
</script>

<script type="text/html" id="barTool">
    {if $userInfo['roleid']==1}
    <a class="layui-btn layui-btn-xs" data-open='{:url("edit")}?id={{ d.id }}' data-title="编辑内容"
       data-full="true">编辑</a>
    <a href='{:url("del",["catid"=>$catid])}?ids={{ d.id }}'
       class="layui-btn layui-btn-danger layui-btn-xs layui-tr-del">删除</a>
    {/if}
</script>

<script type="text/html" id="statusTpl">
    <input type="checkbox" name="status" data-href='{:url("setstate")}?id={{d.id}}' value="{{d.id}}"
           lay-skin="switch"
           lay-text="上架|下架" lay-filter="switchStatus" {{ d.status==1 ? 'checked' : '' }}>
</script>

<script type="text/javascript">
    layui.use('yznTable', function () {
        var table = layui.yznTable;

        var init = {
            table_elem: '#currentTable',
            table_render_id: 'currentTable',
            add_url: '{:url("add")}',
            edit_url: '{:url("edit")}',
            delete_url: '{:url("del")}',
        };

        table.render({
            init: init,
            toolbar: ['refresh', 'add'],
            url: '{:url("index")}',
            search: false,
            cols: [
                [
                    //名称 水票背景图 所属商品分类 所属商品

                    {field: 'id', Width: 80, title: 'ID'},
                    {field: 'name', Width: 100, title: '水票名称', searchOp: 'like'},
                    {field: 'img',Width:200, align: "center", title: '商品图片', templet: '#picTpl'},
                    {field: 'gc_name',Width: 200, title: '所属商品分类', searchOp: 'like'},
                    {field: 'goods_name', Width: 200, title: '所属商品',},
                    {field: 'specs', Width: 200, title: '商品规格说明',},
                    {
                        field: 'status',
                        Width: 100,
                        align: "center",
                        title: '状态',
                        templet: '#statusTpl',
                        unresize: true,
                        selectList: {0: '待审核', 1: '通过'}
                    },
                    {fixed: 'right', Width: 120, title: '操作', toolbar: '#barTool'}
                    // { Width:100, title: '操作',templet: function (d){
                    //     if(d.id=={$userInfo.id}){
                    //         return '<a class="layui-btn layui-btn-xs layui-btn-danger layui-btn-disabled">不可操作</a>';
                    //     }else{
                    //         return yznTable.formatter.tool.call(this,d,this);
                    //     }
                    // },operat: ['edit','delete']}
                ]
            ],
            page: {}
        });

        yznTable.bindevent();
    });
</script>
{/block}